/*Copyright 2014 Rajesh Putta http://www.codesnippets4all.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
* 
*/

package com.codesnippets4all.jthunder.core.execution;

import com.codesnippets4all.jthunder.core.framework.hierarchy.Node;


/*
 * @author Rajesh Putta
 */
public class Status implements IStatus{

	private String taskName;
	
	private StatusType type = null;

	private Object result = null;

	private Node node=null;
	
	private Class<?> clazz=null;
	
	public void setNode(Node node) {
		this.node = node;
	}
	
	public Node getNode() {
		return node;
	}
	
	public String getName() {
		return taskName;
	}
	
	public void setName(String taskName) {
		this.taskName = taskName;
	}

	public Status(StatusType type, Object result) {
		this.type = type;
		this.result = result;
		
		if(result!=null)
		{
			this.clazz = result.getClass();
		}
	}
	
	public Status(StatusType type, Object result, Class<?> resultType) {
		this.type = type;
		this.result = result;
		this.clazz = resultType;
	}
	
	public Status(String taskName, StatusType type, Object result, Class<?> resultType) {
		this.taskName=taskName;
		this.type = type;
		this.result = result;
		this.clazz = resultType;
	}

	public StatusType getType() {
		return type;
	}

	public void setType(StatusType type) {
		this.type = type;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result, Class<?> clazz) {
		this.result = result;
		this.clazz = clazz;
	}
	
	public Class<?> getResultType()
	{
		return this.clazz;
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getResultOfType(Class<T> resultTypeClass)
	{
		return (T)this.result;
	}
}
